Skip to content

Improve escaping of byte, byte str, and c str proc-macro literals#123769

Merged
bors merged 3 commits intorust-lang:masterfrom
dtolnay:literal
Jun 14, 2024
Merged

Improve escaping of byte, byte str, and c str proc-macro literals#123769
bors merged 3 commits intorust-lang:masterfrom
dtolnay:literal

Conversation

@dtolnay
Copy link
Copy Markdown
Member

@dtolnay dtolnay commented Apr 11, 2024

This PR changes the behavior of proc_macro::Literal::byte_character (#115268), byte_string, and c_string (#119750) to improve their choice of escape sequences. 3 categories of changes are made:

  1. Never use \x00. Always prefer \0, which is supported in all the same places.

  2. Never escape \' inside double quotes and \" inside single quotes.

  3. Never use \x for valid UTF-8 in literals that permit \u.

The second commit adds tests covering these cases, asserting the old behavior.

The third commit implements the behavior change and simultaneously updates the tests to assert the new behavior.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-proc-macros Area: Procedural macros T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants